# 低于IE9版本浏览器更新提示
ie9BrowserUpdate = () ->
  # 浏览器版本低提示
  # 获取浏览器类型
  b_name = window?.navigator?.appName
  # 获取浏览器版本信息
  b_version = window?.navigator?.appVersion
  b_versions = b_version.split(";")
  b_version = b_versions[1].replace(/[ ]/g, "")
  if b_name is "Microsoft Internet Explorer"
    if b_version is "MSIE8.0" or b_version is "MSIE7.0" or b_version is "MSIE6.0"
      alert "IE浏览器版本过低，请使用IE9以上版本"
      return

# 调用低于IE9版本浏览器更新处理
ie9BrowserUpdate()

# 修复IE9不支持.classList
ie9ClassListFix = () ->
  try
    if !('classList' of document.documentElement)
      Object.defineProperty HTMLElement.prototype, 'classList', get: ->
        self = this

        update = (fn) ->
          (value) ->
            classes = self.className.split(/\s+/g)
            index = classes.indexOf(value)
            fn classes, index, value
            self.className = classes.join(' ')
            return

        {
          add: update((classes, index, value) ->
            if ! ~index
              classes.push value
            return
          )
          remove: update((classes, index) ->
            if ~index
              classes.splice index, 1
            return
          )
          toggle: update((classes, index, value) ->
            if ~index
              classes.splice index, 1
            else
              classes.push value
            return
          )
          contains: (value) ->
            ! ! ~self.className.split(/\s+/g).indexOf(value)
          item: (i) ->
            self.className.split(/\s+/g)[i] or null
        }
  catch e
    console.warn 'IE8 isnt support classList properties'

# 调用IE9不支持.classList处理
ie9ClassListFix()

# 修复IE9数组不支持indexOF的问题
ie9ArrayIndexOfFix = () ->
  try
    if !Array::indexOf

      Array::indexOf = (elt) ->
        len = @length >>> 0
        from = Number(arguments[1]) or 0
        from = if from < 0 then Math.ceil(from) else Math.floor(from)
        if from < 0
          from += len
        while from < len
          if from of this and @[from] == elt
            return from
          from++
        -1
  catch e
    console.warn 'IE8 isnt support indexOf properties'

# 调用IE9数组不支持indexOF的问题
ie9ArrayIndexOfFix()

# seajs配置
seajs.config
  base: '.'
  plugins: ['shim']
  alias:
    'vue': 'libs/vue/vue.min'
    'vuex': 'libs/vuex/vuex.min'
    'router': 'libs/vue/vue-router.min'
    'resouce': 'libs/vue/vue-resource.min.js'
    'app': 'mods/app'
    'jquery': 'libs/jquery/jquery.min'
    'lodash': 'libs/lodash/lodash.min'
  charset: 'utf-8'
  timeout: 20000
  debug: false

window.ENV = 'production'

# 平台类型
_platform =  window?.navigator?.platform or null

# 设备类型
window.DEVICE_TYPE = if 'Win32' is _platform then 'PC' else 'PHONE'

if 'PC' is window.DEVICE_TYPE
  window.BASE_URL = "http://my.gf.com.cn:8001"
  window.REST_URL = '/apprest'
  # 加载Vue实例、路由、Ajax资源请求、应用主模块
  seajs.use ['vue', 'vuex', 'router', 'resouce', 'lodash', 'app']

else if 'PHONE' is window.DEVICE_TYPE
  # 手机端，设置CSP，以便cordova访问硬件
  # _meta = document.createElement 'meta'
  # _meta['http-equiv'] = "Content-Security-Policy"
  # _meta['content'] = "default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'"
  # window.BASE_URL = "http://yz6970.com"
  window.BASE_URL = "http://118.190.87.200"
  window.REST_URL = "#{window.BASE_URL}/apprest"

  # 加载Vue实例、路由、Ajax资源请求、应用主模块
  seajs.use ['vue', 'vuex', 'router', 'resouce', 'lodash', 'app']

  # # 加载cordova模块，并启动实例
  # seajs.use ['cordova', 'start'], (cordova, cordovaApp) ->
  #   # cordova实例启动
  #   cordovaApp.initialize()
  #   # 加载Vue实例、路由、Ajax资源请求、应用主模块
  #   seajs.use ['vue', 'vuex', 'router', 'resouce', 'lodash', 'app']